###############################################################################
# Appendix Numbers
###############################################################################
#
###############################################################################
# Content
###############################################################################
# 1) Dependencies
# 2) Load Data
# 3) Aggregation for Figure
# 4) Figure
###############################################################################
# 1) Dependencies
###############################################################################
library(readr)
library(dplyr)
library(plyr)
library(ggplot2)
library(gganimate)
library(ggeffects)
library(ggExtra)
library(ggridges)
library(ggrepel)
library(grid)
library(scales)
library(lubridate)
library(extrafont)
library(reshape2)
library(here)
library(ggforce)
library(png)
library(readxl)
library(grid)
library(gridExtra)
library(ggpubr)
library(ggalt)
library(stringr)
###############################################################################
# 2) Load Data
###############################################################################
# Set Path
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
rm(list=ls())


#Load Lists
cand_list_2015 <- read_csv("../support/candidates-2015/candidates_list_final_2015.csv")
cand_list_2019 <- read_csv("../support/candidates-2019/candidates_list_final_2019.csv")

chvote_councilofstates_19 <- read_csv("../support/candidates-2019/2019_chvote_councilofstates.csv")

#filter SR candidates

df19 <- cand_list_2019 %>% filter(council %in% c("SR","SR und NR", "NR und SR"))
df15 <- cand_list_2015 %>% filter(council %in% c("sr","sr & nr"))


# check which candidates from 2015 which were female campaigned again for office (incumbents)

#Women whom were council of state members in 2015 and went for reelection in 2019
reenter <- df19 %>% filter(gender == "f") %>% filter(incumbent == 1) %>% filter(fullname %in% df15$fullname)

#women whom were council of states in 2015 and did not go into reelection in 20119
noenter <- df15 %>% filter(gender == "f") %>% filter(!fullname %in% df19$fullname)


df19 %>% group_by(gender) %>% dplyr::summarise(n = n()) %>% dplyr::mutate(f = n / sum(n))
df15 %>% group_by(gender) %>% dplyr::summarise(n = n()) %>% dplyr::mutate(f = n / sum(n))
chvote_councilofstates_19  %>% group_by(gender) %>% dplyr::summarise(n = n()) %>% dplyr::mutate(f = n / sum(n))
